package offer.algorithm;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/18 21:30
 */
public class OctToBin10 {

    public static String getBin(int num) {
        StringBuilder sb = new StringBuilder();
        while (num != 0) {
            sb.append(num & 1);
            num = num >> 1;
        }
        return sb.reverse().toString();
    }

    public static int getCount(int num){
        int count = 0;
        int flag = 1;
        while (flag <= num){
            if((num & flag) != 0)
                count++;
            flag = flag << 1;
        }
        return count;
    }

    public static int getCountHighLevel(int num){
        int count = 0;
        while(num != 0){
            ++count;
            num = num & (num - 1);
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(getCountHighLevel(-2147483648));
    }

}
